package todlu.RssReader;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

final class CategoryItemHolder {
	public ImageView logo;
	public TextView name;
	public ImageView more;
}

public class CategoryItemAdapter extends BaseAdapter {
	private List<HashMap<String, Object>> list;
	private Context context;
	private CategoryItemHolder holder;
	private LayoutInflater inflater;
	
	public CategoryItemAdapter(Context context, List<HashMap<String, Object>> list)
	{
		this.context = context;
		this.list = list;
		inflater = LayoutInflater.from(context);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		holder = null;

		if (convertView == null) {
			holder = new CategoryItemHolder();

			convertView = inflater.inflate(R.layout.add_channel_item, null);

			holder.logo = (ImageView) convertView
					.findViewById(R.id.categoryIcon);
			holder.name = (TextView) convertView
					.findViewById(R.id.categoryName);
			holder.more = (ImageView) convertView.findViewById(R.id.moreContent);

			convertView.setTag(holder);

			holder.name.setText((String) list.get(position).get("Name"));		//设置Item的文字
			
			if(list.get(position).get("Logo") != null)							//设置Item的图标
			{
				holder.logo.setImageDrawable((Drawable)list.get(position).get("Logo"));
			}
		} 
		else 
		{
			holder = (CategoryItemHolder) convertView.getTag();

			holder.name.setText((String) list.get(position).get("Name"));		//设置Item的文字
			
			if(list.get(position).get("Logo") != null)							//设置Item的图标
			{		
				holder.logo.setImageDrawable((Drawable)list.get(position).get("Logo"));
			}
		}

		return convertView;
	}

}
